package com.example.common;

import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;

/**
 * <h1></h1>
 */

@Data
@ConfigurationProperties(prefix = "jwt")
@Component
public class JwtProperties {

    /**
     * 密钥类型，可选值为jks,rsa,secret，默认secret
    */
    private String type = "secret";

    /**
     * 密钥
     */
    private String secret;
    /**
     * 过期时间，单位毫秒
     */
    private Long expiration;
    /**
     * 请求头参数名称
     */
    private String header;



    public SecretKey getSecretKey() {
        byte[] encodeKey = Decoders.BASE64.decode(secret);
        return Keys.hmacShaKeyFor(encodeKey);
    }


}
